package com.aaa.hospital.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Author: HJT
 * @DateTime: 2022/2/13 18:14
 * @Description: TODO
 */
public class MyAOP {
    private static Logger log =  Logger.getLogger(MyAOP.class);

    private long start = 0;

    public void haha(JoinPoint point){

        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        HttpServletResponse response = requestAttributes.getResponse();

        String addr = request.getRemoteAddr();
        String uri = request.getRequestURI();
        Object[] args = point.getArgs();


        start = System.currentTimeMillis();
        log.info("===================请求的地址是:================="+addr);
        log.info("===================请求的路径是:================="+uri);
        log.info("===================请求的参数是:================="+ Arrays.toString(args));
    }

    public void hehe(){
        long end = System.currentTimeMillis();
        log.info("=================耗时================="+ (end-start));
        log.info("=================结束了=================");
    }

}
